/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-12-20 14:11:11
 * Last Modified: 2016-01-21 17:17:48
 * File Name: controllers/passportadmin.go
 * Description:
 */
package controllers

import (
	"fmt"

	"passport/admin"
	"passport/errorcode"
)

type PassportAdminController struct {
	URLSignController
}

/*
	删除userid在账号系统中有所有数据
*/
func (p *PassportAdminController) DeletePassportByUserid() {
	defer p.Output("DeletePassportByUserid")

	clientIp := p.Ctx.Input.IP()
	if clientIp != "127.0.0.1" && clientIp != "0.0.0.0" {
		p.Resp["code"] = errorcode.EC_GL_INVALID_IP
		p.Resp["msg"] = fmt.Sprintf("invalud ip address for %s", clientIp)
		return
	}

	uid := p.GetString("uid", "")
	err := admin.GetPassportAdmin().DeletePassportByUserid(uid)
	if err == nil {
		p.Resp["code"] = errorcode.EC_GL_SUCCESS
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_SUCCESS)
		return
	}
	p.Resp["code"] = errorcode.EC_ADMIN_DELETE_PASSPORT_ERROR
	p.Resp["msg"] = err.Error()
}
